package com.example.zg3_park.fg

import android.util.Log
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.launcher.ARouter
import com.example.lib_base.entity.NoticeEntityResultItem
import com.example.lib_base.mvvm.BaseFragment
import com.example.zg3_park.adapter.NoticeAdapter
import com.example.zg3_park.adapter.OnItemClickListener
import com.example.zg3_park.adapter.OnItemLongClickListener
import com.example.zg3_park.databinding.FragmentHomeBinding
import com.example.zg3_park.notice.NoticeViewModel
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch

@AndroidEntryPoint
class HomeFragment : BaseFragment<FragmentHomeBinding,NoticeViewModel>() {
    val noticeAdapter by lazy { NoticeAdapter() }
    override fun intiView() {
        binding.rvGg.apply {
            adapter = noticeAdapter
            layoutManager = LinearLayoutManager(requireContext())
        }

        binding.ivNews.setOnClickListener {
            ARouter.getInstance().build("/app/NewsActivity").navigation()
        }

        noticeAdapter.setOnItemClickListener(object : OnItemClickListener {
            override fun onItemClick(position: Int, item: NoticeEntityResultItem) {
                Log.i("======","${position},${item.toString()}")
            }
        })

        noticeAdapter.setOnItemLongClickListener(object : OnItemLongClickListener {
            override fun onItemLongClick(item: NoticeEntityResultItem): Boolean {
                Log.i("===","${item.toString()}")
                return true
            }
        })

        //跳转
        binding.ivCarType.setOnClickListener {
            ARouter.getInstance().build("/app/CarTypeActivity").navigation()
        }

    }

    override fun intiData() {
        lifecycleScope.launch {
            vm.getNotices().collect(){
                noticeAdapter.submitData(it)
            }
        }
    }

}